import { utilJs } from "@/utils/common.js";
import { appRouterChange } from "@/mixin/appRouterPush.js";
import { goDetails } from "@/utils/goDetails.js"
export const custIndex = {
  data() {
    return {
      dataList: [],
      navMap: global.navMap,
      ckFrom: global.ckFrom,
    }
  },
  mixins: [appRouterChange],
  methods: {
    iosAppRouteChange(toPath) {
      if (utilJs.isIOSApp()) {
        window.webkit.messageHandlers.iosWechatRoute.postMessage(toPath);
      } else if (utilJs.isAndoridNewApp()) {
        let data = {
          path: toPath
        }
        window.androidWechatRoute.doAction(JSON.stringify(data))
      } else {
        this.$routerGo(this, "push", { path: toPath });
      }
    },
    // 首页自定义模板导航跳转
    commonModuleRouterPush(data) {
      if ((!data || (data && data.pageName == 'PREVIEW_INDEX')) || (data.navId == 'daySign' && localStorage.getItem('isWxApp'))) return
      let curNavId = data ? data.navId : '';
      switch (curNavId) {
        case "mentor":
          this.iosAppRouteChange("/homePage/course/lecturerDetail?lecturerId=" + data.lecturerId);
          break;
        case "gzhShow":
          this.$store.commit('updateShowAttentionQr', true);
          break;
        case "addTeacher":
          this.$store.commit('updateShowAddTeacher', true);
          break;
        case "custom": case "microMall": case "": // 自定义导航栏 跳转链接 空也算自定义吧 防止后台保存空的情况
          let url = data.url || data.navHref;
          // 定制刀法平台传递token
          let companyId = localStorage.getItem('companyId');
          if (companyId == 'jz5r22' && curNavId == "custom" && data.isnavigation) {
            url = `${url}${JSON.stringify(utilJs.getQueryObject(url)) === '{}' ? '?' : '&'}companyToken=${localStorage.getItem("token")}`
          }
          this.goTargetUrl(url)
          break;
        case "upgradeVip":
          let toPath = "";
          toPath = data.upgradeMemberJump == 1 ? "/member/vip/vipUp" : "/member/vip/vipUp?type=23";
          this.iosAppRouteChange(toPath);
          break;
        case "vipfree": case "svipfree":
          this.iosAppRouteChange("/member/vip/vipRecommend?typeNum=" + (curNavId == "vipfree" ? 2 : 4));
          break;
        case "knowledge":
          this.iosAppRouteChange("/homePage/package/packageList");
          break;
        case "shoppe":
          this.iosAppRouteChange("/mall/shopDetail/shopDetail?shopNo=" + data.mgId);
          break;
        case "chooseClassify":
          if (!data.info) return
          // 跳转到对应分类商品列表中
          this.iosAppRouteChange(`/homePage/course/catDetailList?cateId1=${data.info.level1CatId}&cateId2=${data.info.level2CatId}&cateId3=${data.info.level3CatId}&name=${data.info.name}`);
          break;
        case "chooseGoods":
          if (!data.info) return
          let id = data.info.id, prodType = data.info.prodType, courseType = data.info.courseType;
          if ([110, 111, 112].includes(data.info.prodType)) {
            prodType = this.ckFrom.course;
          }
          goDetails(this, prodType, id, '', courseType);
          break;
        default:
          this.iosAppRouteChange(this.navMap[curNavId].link);
          break;
      }
    },
  },
};
